//
//  WBNetworkManager+E.swift
//  Weibo
//
//  Created by FF on 16/12/20.
//  Copyright © 2016年 Cold Wind. All rights reserved.
//

import Foundation

// MARK: - 封装新浪微博的网络请求方法
extension WBNetworkManager {
    
    /// 加载微博数据字典数组
    ///
    ///   - since_id: 则返回ID比since_id大的微博（即比since_id时间晚的微博），默认为0。
    ///   - max_id: ，则返回ID小于或等于max_id的微博，默认为0。
    /// - Parameter completion: 完成回调 【list:微博字典数组】
    func statusList(since_id: Int64 = 0,max_id: Int64 = 0,completion:@escaping (_ result: [[String: Any]]?,_ isSuccess: Bool) -> ()) {
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"
        //let params = ["access_token": "2.00wCA74B0RWfQB71a4f13865ElJr1D"]
        
        let params = ["since_id": since_id,
                      "max_id": max_id > 0 ? max_id - 1 : 0]
        
        tokenRequest(URLString: urlString, parameters: params) { (json, isSuccess) in
            // 从json 中获取 statuses 字典数组
           let result = (json as AnyObject)["statuses"] as? [[String: Any]]
           completion(result, isSuccess)
        }
    }
}
